/**
 * * 防抖
 * * 用法 v-debounce:200="submit"
 */
export default (app) => {
  app.directive('debounce', {
    mounted(el, bindings) {
      let delay = bindings.arg
      if (!delay) delay = 500

      let timer
      el.addEventListener('click', () => {
        if (timer) clearTimeout(timer)
        timer = setTimeout(() => {
          bindings.value()
        }, delay)
      })
    }
  })
}
